package com.itheima.info.manger.system.service;

import com.itheima.info.manger.system.dao.BaseStudentDao;
import com.itheima.info.manger.system.dao.OtherStudentDao;
import com.itheima.info.manger.system.dao.StudentDao;
import com.itheima.info.manger.system.domain.Student;
import com.itheima.info.manger.system.factory.StudentDaoFactory;

import javax.print.attribute.standard.MediaSize;

public class StudentService {
    //private StudentDao dao = new StudentDao();

    private BaseStudentDao dao = StudentDaoFactory.getStudentDao();

    //增
    //参数 学生对象
    //返回值 成功或失败
    public boolean addStudent(Student student) {
        return dao.addStudent(student);
    }

    //删
    //参数 学号
    //返回值
    public void deleteStudent(String sid) {
       dao.deleteStudent(sid);
    }

    //改
    //参数 学号   新的学生对象
    public void updateStudent(String sid, Student newStu) {
       dao.updateStudent(sid,newStu);
    }

    //查
    //参数 没有参数
    //返回值 学生数组
    public Student[] findAllStudents() {
       Student[] students = dao.findAllStudents();
       for (int i = 0; i < students.length; i++) {
          //students[i]
          Student stu = students[i];
          if(stu!=null){
             return students;
          }
       }
       return null;
    }
    //判断学号是否存在
    public boolean isExist(String sid) {
       Student[] students = dao.findAllStudents();
       for (int i = 0; i < students.length; i++) {
          //students[i]
          Student stu = students[i];
          if(stu!=null&&sid.equals(stu.getSid())){
             return true;
          }
       }
        return false;
    }


}
